﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class StartPanel : MonoBehaviour
{
    private Slider loadSlider;
    private AsyncOperation operation;
    private float timer=0;
    private GameObject handle;

    private void Start()
    {
        loadSlider = GameObject.Find("Slider").GetComponent<Slider>();
        handle = GameObject.Find("Handle");
        operation = SceneManager.LoadSceneAsync("MainMenu");
        operation.allowSceneActivation = false;
    }

    private void Update()
    {
        float targetValue = operation.progress-0.5f;

        if (operation.progress >= 0.1f)
        {
            timer += Time.deltaTime;

            targetValue += timer;
            if ((1 - targetValue) <= 0.01)
            {
                targetValue = 1.0f;
            }
        }
        loadSlider.value = targetValue;
        handle.transform.localScale = new Vector3(1 - targetValue, 1 - targetValue, 1);

        if (loadSlider.value >=1)
        {
            operation.allowSceneActivation = true;
        }
    }
}
